package com.feicheng.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;

import java.time.Instant;

@Slf4j
@Component
public class AsyncService {

    @Autowired
    ThreadPoolTaskScheduler scheduledExecutorService;

    public void runScheduler(AyscnRunnable runnable, long mins, String name) {
        scheduledExecutorService.schedule(() -> {
            log.info(name+"执行开始");
            String result = runnable.run();
            log.info(name+"执行结束："+result);
        }, Instant.now().plusSeconds(mins * 15));
    }

    public static interface AyscnRunnable {
        public String run();
    }
}
